// global dependencies
import '../style/index.less';

import $ from 'jquery';

import './common';
import 'bootstrap';
import BootstrapDialog from 'bootstrap3-dialog';
import './plugins/index';
import 'datatables';
import 'ztree';
import './plugins/ajax';
import './plugins/device';
import './plugins/dialog';
import './plugins/chart';
import './plugins/date'; // 时间工具
import './plugins/jquery.textEdit';
import _ from 'lodash';

// application modules
import './demo/index';
import './tree/index';
import pages from './pages/index';
import useInfoHtml from '../assets/partials/user-info.html'

//添加分组
import './pages/group-add';
//编辑频道
import './pages/channel-edit';
//添加设备
import './pages/device-add';

$.actions('root', $.extend($.actions('root'), {
    log: console.log
}));

$.ajaxSetup({
    cache: false
    // error: e => console.log(e)
});

$(() => {

    $("#logout").click(function(e) {
        $.get('/portal/logout.do', function(res) {
            window.location.href = "/login.html";
        });
    });

    $("#userInfo").click(function(e) {
        $.dialogShow({
            title: "个人信息",
            message: $("<div>").append(useInfoHtml)
        });
    });

    $(document).on("click", ".tree-node", function(event) {
        event.stopPropagation();
        event.preventDefault();
        $('#tree-panel').find(".tree-node.selected").removeClass("selected");
        $(this).addClass("selected");
        let $table = $(document).find("table");
        let paramGroup = $table.attr("data-param-group");
        if (paramGroup == undefined) {
            let dataTable = $table.DataTable();
            dataTable.draw();
        }

    });

    // console.log($('.tree').find(".group-action.hidden").length)

    pages.initialize();
});
